package com.csoa.community.widget;

import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.collect.community.R;
import com.csoa.community.bean.IssueGroupBean;

public class PopWin {
	public View view;
	Activity mpthis;
	PopupWindow mPopupWindow;
	int mheight;

	public PopWin(Activity pthis) {
		mpthis = pthis;
		mPopupWindow = null;
	}

	public void setY(int y) {
		mheight = y;
		Log.d("PopWin", "setY:" + mheight);
	}

	public void dismiss() {
		Log.d("PopWin", "dismiss");
		if (mPopupWindow != null) {
			mPopupWindow.dismiss();
			mPopupWindow = null;
			Log.d("PopWin", "dismiss ok");
		}
	}

	TextView tv_showText = null;
	ImageView in1 = null;
	ImageView in2 = null;
	TextView tv = null;
	TextView tv1 = null;
	private Button btnConfirm;
	private Button btnCancel;
	private OnConfirmClickListener onConfirmClickListener;
	private OnCancelClickListener onCancelClickListener;

	public void ShowWin(IssueGroupBean mIssueGroup) {
		dismiss();
		View foot_popunwindwow = null;

		LayoutInflater LayoutInflater = (LayoutInflater) mpthis
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		foot_popunwindwow = LayoutInflater.inflate(R.layout.plug_popwindow,
				null);
		TextView tv = (TextView)foot_popunwindwow.findViewById(R.id.tvTitleWindow);
		tv.setText("欢迎" + mIssueGroup.unit + "课题组   " + mIssueGroup.writer + "登录   物种信息采集移动端");

		mPopupWindow = new PopupWindow(foot_popunwindwow,
				600, 300);
		mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
		Log.d("PopWin", "" + mheight);
		mPopupWindow.showAtLocation(mpthis.findViewById(R.id.totalLayout),
				Gravity.CENTER | Gravity.CENTER, 0, 0);
		mPopupWindow.update();

		btnConfirm = (Button) foot_popunwindwow
				.findViewById(R.id.btnConfirm);
		btnCancel = (Button) foot_popunwindwow.findViewById(R.id.btnCancel);
		btnConfirm.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onConfirmClickListener.click();
			}
		});
		btnCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onCancelClickListener.click();
//				dismiss();
			}
		});
	}
	
	public interface OnConfirmClickListener {
		public void click();
	}

	public void setOnConfirmClickListener(
			OnConfirmClickListener onConfirmClickListener) {
		this.onConfirmClickListener = onConfirmClickListener;
	}
	
	public interface OnCancelClickListener {
		public void click();
	}

	public void setOnCancelClickListener(
			OnCancelClickListener onCancelClickListener) {
		this.onCancelClickListener = onCancelClickListener;
	}

}
